// void, Obj This, Obj Other

Unit  this;
Ship  ship;
point pt;
int   time;
int   dist;
bool group;

Sleep(rand(100)+30);
this = This.AsUnit;
if (.IsValid) {// leave parry mode at new command
	.SetParryMode(false);
	
	if(.hero.IsValid){
		if(.hero.HasItem("irage_battle")){
			Sleep(rand(200)+30);
			.AddCommand(true, "engage");
			return;
		} else if(.hero.HasItem("irage_battle_stand")){
			Sleep(rand(200)+30);
			.AddCommand(true, "stand_position");
			return;
		}
	}
	
	if(.item_count > 0){
		Item item;
		
		item = .FindItem("Terrain bonus I");
		if(item.IsValid)
			.RemoveItemsOfType("Terrain bonus I");
		else {
			item = .FindItem("Terrain bonus II");
			if(item.IsValid)
				.RemoveItemsOfType("Terrain bonus II");
			else {
				item = .FindItem("Terrain bonus III");
				if(item.IsValid)
					.RemoveItemsOfType("Terrain bonus III");
				else {
					item = .FindItem("Terrain bonus IV");
					if(item.IsValid)
						.RemoveItemsOfType("Terrain bonus IV");
				}
			}
		}
	}
}

if(.IsValid)
	if(.IsMilitary)
		if(.speed_factor < 100)                                  
			.SetSpeedFactor(100);
			
ship = Other.AsShip;
pt = ship.pos;
time = 0;

group = true; 

while( 1 )
{
	//pr("unit board common");
	if( .DistTo(pt) > 500)
		{ if( .Goto( pt, 120, 2000, true, -1 )) Sleep( 100 ); }
	else
		{ if( .GotoEnter( pt, 120, 2000, true, -1 )) Sleep( 100 ); }
  if (!ship.IsAlive) return;
	time += 2000;
	dist = Dist( .posRH, ship.pos );
	if( ( dist > 4000 && time > 12000 ) ||
		( dist > 2000 && time > 8000 ) ||
		( dist > 1000 && time > 4000 ) ||
		( dist < 500 ))
	{
		pt = ship.pos;
		time = 0;
	}
	if( ship.BoardUnit( this )) return;
	if( ship.UnitsCount == ship.UnitsMax ) return;
	if( ship.NumUnitsToBoard == 0 ) return;
}
